"""

    将app初始化相关的操作放入到init的方法中
    从而将启动类的代码抽离出来

"""
from flask import Flask
from app.models.base import db
from flask_login import LoginManager
from flask_mail import Mail

login_manager = LoginManager()
mail = Mail()

def create_app():
    """
    创建app对象
    :return:
    """
    app = Flask(__name__)
    # 从模块里面加载配置文件
    app.config.from_object('app.secure')
    app.config.from_object('app.setting')
    register_blueprint(app)

    db.init_app(app)
    db.create_all(app=app)
    login_manager.init_app(app)
    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录或者注册'
    mail.init_app(app)
    return app


def register_blueprint(app):
    """
    注册蓝图
    :param app:
    """
    from app.web import web
    app.register_blueprint(web)